'use strict';

const Service = require('egg').Service;

class UserService extends Service {
  async getJsSdk() { 
    let grant_type = "client_credential";//获取access_token填写client_credential   
    let AppId="wxa97639ce5ff70793";//第三方用户唯一凭证  
    let secret="34cfddab1b02a9a876d435ea9563414b";//第三方用户唯一凭证密钥，即appsecret   
    //这个url链接地址和参数皆不能变  
    const { ctx, app } = this;
    let url = `https://api.weixin.qq.com/cgi-bin/token?grant_type=${grant_type}&appid=${AppId}&secret=${secret}`;  
  const {data} = await app.curl(url, {
      method: 'GET',
      dataType: 'json',
    });
    return data.access_token
  }
  async getTicket(access_token) {
    const { ctx, app } = this;
    const url = `https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=${access_token}&type=jsapi`;//这个url链接和参数不能变  
    const {data} = await app.curl(url, {
      method: 'GET',
      dataType: 'json',
    });
    return data.ticket
  }
  async jssdkVoice(mediaId) {
    const writing = await wx.translateVoice({
      localId: mediaId, // 需要识别的音频的本地Id，由录音相关接口获得
      isShowProgressTips: 1, // 默认为1，显示进度提示
    });
    console.log(writing)
  }
}
module.exports = UserService